import java.util.LinkedHashSet;
import java.util.ArrayList;
/**
 * This class gives a summary of usefull statistics of the festival: top 3 of the most liked band, top 3 of the most attented band and top3 of the most commended band.
 * 
 * @author Mathieu Reymond & Jonathan Smet 
 * @version 03/05/11
 */
public abstract class Statistics
{
    
   /**
     * Gives a list of 3 items that have the most "likes" in the right order. 
     * 
     * @return The methode will return a LinkedHashSet including the names of all the three most-liked performances.
     */
    public static LinkedHashSet<String> mostLiked()
    {
        LinkedHashSet<String> mostLiked= new LinkedHashSet <String>();
        
        String performanceList[] = LineUp.getNameList();
        ArrayList<String> userLikeList = new ArrayList<String>();
        ArrayList<Integer> counter = new ArrayList<Integer>();
        
        for(int index = 0; index < performanceList.length; index++)
        {
            counter.add(0);
        }
        
        for(int index =0 ; index < performanceList.length; index++)
        {
            
            for(int i = 0; i < UserData.getNameList().length; i++)
            {
                userLikeList = UserData.getUserData().get(UserData.getNameList()[i]).getLikeList();
                
                for(int j = 0; j < userLikeList.size(); j++)
                {
                    if( userLikeList.get(j).equals(performanceList[index]))
                    {
                        int plus = counter.get(index);
                        plus++;
                        counter.set(index, plus);
                        
                    }
                }
            }
        }
        
        for(int c = 0; c < 3; c++)
        {
            int positionMaximum = 0;
            int i =0;
            while( i < counter.size())
            {
                if(positionMaximum == i && mostLiked.contains(performanceList[i]))
                {
                    positionMaximum++;
                }
                
                if ((!mostLiked.contains(performanceList[i])) &&  counter.get(i) >= counter.get(positionMaximum) )
                {
                    positionMaximum = i;
                }
                i++;
            }
            
            mostLiked.add(performanceList[positionMaximum]);
        }
        
        return mostLiked;
    }
    
   /**
     * Gives a list of 3 items that are the most planned, in the right order. 
     * 
     * @return The methode will return a LinkedHashSet including the names of all the three most-attented performances.
     */
     public static LinkedHashSet<String> mostAttend()
    {
        LinkedHashSet<String> mostAttend= new LinkedHashSet <String>();
        
        String performanceList[] = LineUp.getNameList();
        ArrayList<String> userAttendList = new ArrayList<String>();
        ArrayList<Integer> counter = new ArrayList<Integer>();
        
        for(int index = 0; index < performanceList.length; index++)
        {
            counter.add(0);
        }
        
        for(int index =0 ; index < performanceList.length; index++)
        {
            
            for(int i = 0; i < UserData.getNameList().length; i++)
            {
                userAttendList = UserData.getUserData().get(UserData.getNameList()[i]).getPlanning().getPlanningList();
                
                for(int j = 0; j < userAttendList.size(); j++)
                {
                    if( userAttendList.get(j).equals(performanceList[index]))
                    {
                        int plus = counter.get(index);
                        plus++;
                        counter.set(index, plus);
                        
                    }
                }
            }
        }
        
        for(int c = 0; c < 3; c++)
        {
            int positionMaximum = 0;
            int i =0;
            while( i < counter.size())
            {
                if(positionMaximum == i && mostAttend.contains(performanceList[i]))
                {
                    positionMaximum++;
                }
                
                if ((!mostAttend.contains(performanceList[i])) &&  counter.get(i) >= counter.get(positionMaximum) )
                {
                    positionMaximum = i;
                }
                i++;
            }
            
            mostAttend.add(performanceList[positionMaximum]);
        }
        
        return mostAttend;
    }
    
     /**
     * Gives a list of 3 items that are the most commented, in the right order 
     * 
     * @return The methode will return a LinkedHashSet including the names of all the three most-co performances.
     */
    public static LinkedHashSet<String> mostComment()
    {
        LinkedHashSet<String> mostComment= new LinkedHashSet <String>();
        int t=0;

        while(t<3)
        {
            int positionMaximum = 0;
            int i =0;
            while( i < LineUp.getNameList().length)
            {
                if(positionMaximum == i && mostComment.contains(LineUp.getNameList()[i]))
                {
                    positionMaximum++;
                }
                
                if ((!mostComment.contains(LineUp.getNameList()[i])) &&  LineUp.getLineUp().get(LineUp.getNameList()[i]).getAmountComments() >= LineUp.getLineUp().get(LineUp.getNameList()[positionMaximum]).getAmountComments() )
                {
                    positionMaximum = i;
                }
                i++;
            }
            
            mostComment.add(LineUp.getNameList()[positionMaximum]);
            t++;
        }  
        
        return mostComment;
    }
}
